import * as React from "react";

export interface FloraType {
    type: 'speciesName' | 'genus' | 'family'
    genusLa?: string
    genusName?: string
    flora?: string
    floraNumber?: string
    floraAreaType?: string
    floraAreaName?: string
    floraAreaNameEn?: string
    familyLa?: string
    speciesName?: string
}

export interface SpeciesInfo {
    id?: string
    type: string
    researchType: string
    researchId?: string
    layerName?: string
    tableIndex?: string
    blockId?: string
    url?: string
    speciesName?: string
    species_name?: string
    rowId: string
    canorical_me: string
    kingdom: string
    phylum: string
    class: string
    order: string
    family: string
    kingdom_c: string
    phylum_c: string
    class_c: string
    order_c: string
    family_c: string
    genus: string
    genus_c: string
    species_c: string
    altitude?: string
    infraspecies_c: string
    infraspecies_c2: string
    Commom_name: string
    state_protection_grade: string
    endangered: 'all' | 'DD' | 'LC' | 'NT' | 'VU' | 'EN' | 'CR' | 'EW' | 'EX'
    CIETS: string
    latitude: string
    longitude: string
    remark: string
    voiceList: string
    imageList: string
    _imageList: any[]
    microHabitat: string
    serialNumberAndCode: string
    createDate: number,
    identificationStatus: string
    originSpeciesName: string
    is_delect: 0 | 1
    originType: string
    province_protection_grade: string
    province: string
    localId: string
    customAddress: string
    speciesFlora?: FloraItem
    genusFlora?: FloraItem
    familyFlora?: FloraItem
    speciesType?: string
}

export interface ColSpanInfo {
    rowIndex: number
    colIndex: number
    colSpan: number
}

export interface RowSpanInfo {
    rowIndex: number
    colIndex: number
    rowSpan: number
}

export type ParagraphInlineStyleName =
    'inlineStyle_normal'
    | 'inlineStyle_italic'

interface ParagraphInlineStyleRange {
    offset: number,
    length: number,
    name: ParagraphInlineStyleName
}

export type ParagraphType =
    'heading1'
    | 'heading2'
    | 'heading3'
    | 'heading4'
    | 'heading5'
    | 'heading6'
    | 'normalParagraph'
    | 'tableName'
    | 'smallTableName'
    | 'tableAfterDesc'
    | 'failureTitle'
    | 'failureDesc'

export type InlineTableStyle =
    'normalTable'                     //默认无格式
    | 'speciesBook'             //物种名录表
    | 'protectionSpeciesBook'  //保护物种表
    | 'genusCollectTable'      //属种统计表
    | 'failureTable'

export interface ReportParagraphBlock {
    blockId?: string
    type: 'Text' | 'Table' | 'LaTex'
    pageBreakBefore?: boolean,
    pageBreakAfter?: boolean
    text?: string
    paragraphInlineStyleRanges?: ParagraphInlineStyleRange[],
    paragraphType?: ParagraphType
    tableData?: string[][]
    isSubTable?: boolean
    tableHeaderRowNumber?: number
    tableStyle?: InlineTableStyle
    rowSpanInfoList?: RowSpanInfo[]
    colSpanInfoList?: ColSpanInfo[]
    inlineStyleRanges?: any[]
    tableName?: string
}

export interface CreateSpeciesBookParams {
    mergedRowDataList: SpeciesInfo[],
    isProtection?: boolean
}

export interface CreateSpeciesStatisticsParams {
    mergedRowDataList: SpeciesInfo[]
}

export interface CreateFloraReportParams {
    mergedRowDataList: SpeciesInfo[],
    floraQueryResult: FloraQueryResult,
    type: 'analys' | 'report'
}

export interface EnvironmentalFactorAnalysisParams {
    airMonitoringSheetData: string[]
    waterEnvironmentSheetData: string[]
    soilMonitoringSheetData: string[]
    year: string
}

export interface VegetationAndEcosystemAnalysisParams {
    ecosystemTypeSheetData: any[]
    vegetationTypeSheetData: any[]
}

export interface LandUseTypeAnalysisParams {
    workSheet: string[][]
}

export interface ManagementEffectivenessEvaluationParams {
    sheetData1: any[],
    sheetData2: any[]
}

export interface StatisticalAnalysisTools {
    createSpeciesBook: (params: CreateSpeciesBookParams) => ReportGenerateResult
    createSpeciesStatisticsReport: (params: CreateSpeciesStatisticsParams) => ReportGenerateResult
    createFloraReport: (params: CreateFloraReportParams) => ReportGenerateResult
    environmentalFactorAnalysis: (params: EnvironmentalFactorAnalysisParams) => ReportParagraphBlock[]
    vegetationAndEcosystemAnalysis: (params: VegetationAndEcosystemAnalysisParams) => ReportParagraphBlock[]
    landUseTypeAnalysis: (params: LandUseTypeAnalysisParams) =>  ReportParagraphBlock[]
    socialEconomicStatistics: (params: LandUseTypeAnalysisParams) => ReportParagraphBlock[]
    managementEffectivenessEvaluation: (params: ManagementEffectivenessEvaluationParams) => ReportParagraphBlock[]
    managementOrganizationAndPersonnel:  (params: LandUseTypeAnalysisParams) => ReportParagraphBlock[]
    // createImportantValueAnalysis: (params: CreateSpeciesStatisticsParams) => ReportGenerateResult
    // createDiversityIndexAnalysis: (params: CreateSpeciesStatisticsParams) => ReportGenerateResult
}

export interface Taxon {
    name: string;
    latin: string;
    children: Record<string, Taxon>;
}

export interface Species {
    name: string;
    latin: string;
    national: string;
    provincial: string;
    iucn: string;
    cites: string;
    children?: Record<string, Taxon>;
}

export interface SpeciesDataWithIndexSignatures extends SpeciesInfo {
    [index: string]: any;
}

export interface CategoryWithChildren {
    [index: string]: Taxon | Species;
}

export interface TableGenerateResult {
    tableData?: string[][],
    tableHeaderRowNumber?: number
    tableStyle: InlineTableStyle,
    tableColSpanInfoList?: ColSpanInfo[]
    tableRowSpanInfoList?: RowSpanInfo[]
}

export interface ReportGenerateResult {
    reportParagraphList?: ReportParagraphBlock[],
    matchFailureParagraphList?: ReportParagraphBlock[]
}

export type ExtractCategory =
    'order'       //目
    | 'family'    //科
    | 'genus'     //属
    | 'species'   //种


export interface FloraItem {
    create_time: number
    familyLa: string
    flora: string
    floraDistribution: string
    floraDistributionEn: string 
    floraSubDistribution: string
    genusLa: string
    id: number
    speciesName: string
    type: "species" | 'genus' | 'family'
}

type ResearchNameDict = 'commonResearch' | 'birdResearchLine' | 'insectResearchLine' | 'beastResearchLine' |
    'reptileResearchLine' | 'plantResearchLine' | 'insectResearchPoint' | 'fishResearchPoint' |
    'beastResearchPoint' | 'birdResearchPoint' | 'birdResearcDisPoint' | 'fungusResearchCollect' |
    'plantResearchCollect' | 'waterResearchCollect' | 'soilResearchCollect' | 'vegetationResearchCollect' |
    'landResearchCollect' | 'forestResearchPlot' | 'shrubResearchPlot' | 'grassResearchPlot' | 'humanActivity' |
    'naturalDisaster' | 'speciesDistribution' | 'workPhoto' | 'vegetationResearchPoint' | 'wetlandResearchPlot'

export type TypeMergedRowData = {
    id?: string
    type: string
    researchType: ResearchNameDict
    researchId?: string
    layerName?: string
    tableIndex?: string
    blockId?: string
    url?: string
    speciesName?: string
    species_name?: string
    rowId: string
    canorical_me: string
    kingdom: string
    phylum: string
    class: string
    order: string
    family: string
    kingdom_c: string
    phylum_c: string
    class_c: string
    order_c: string
    family_c: string
    genus: string
    genus_c: string
    species_c: string
    altitude?: string
    infraspecies_c: string
    infraspecies_c2: string
    Commom_name: string
    state_protection_grade: string
    endangered: 'all' | 'DD' | 'LC' | 'NT' | 'VU' | 'EN' | 'CR' | 'EW' | 'EX'
    CIETS: string
    latitude: string
    longitude: string
    remark: string
    voiceList: string
    imageList: string
    _imageList: any[]
    microHabitat: string
    serialNumberAndCode: string
    createDate: number,
    identificationStatus: string
    originSpeciesName: string
    is_delect: 0 | 1
    originType: string
    province_protection_grade: string
    province: string
    localId: string
    customAddress: string
    surveyDate: number
    speciesFlora?: FloraItem
    genusFlora?: FloraItem
    familyFlora?: FloraItem
}

export interface FloraQueryResult {
    familyList: FloraItem[],
    genusList: FloraItem[],
    speciesList: FloraItem[]
}

export interface NameLaItem {
    nameZH?: string
    nameLA?: string
    speciesType?: string
}

export interface FloraStatisticsItem {
    floraName: string
    floraItem: FloraItem
    speciesNameUniquenList: NameLaItem[]
    genusNameUniquenList: NameLaItem[]
    familyNameUniquenList: NameLaItem[]
    times: number
}

export interface ResearchRecordItemRowDataElement {
    id?: string
    speciesName: string
    numberOfPlants?: string  //株数
    breastDiameter?: string  //胸径
    multiplicity?: string    //多度
    coverage?: string        //盖度
    treeHeight?: string      //高度
    averageHeight?: string   //平均高
    multipleOptimalityDegree?: string  //多优度-集群度
    speciesCout?: string
}

export interface ResearchRecordItem {
    serialNumberAndCode: string
    researchType: ResearchNameDict
    rowDataList: ResearchRecordItemRowDataElement[],
}

declare const statisticalAnalysisTools: StatisticalAnalysisTools;
export default statisticalAnalysisTools;